<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Shopclick;
use App\Models\User;
use App\Models\User as Model;
use Carbon\Carbon;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class ShopclickController extends AdminController
{


    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Shopclick(), function (Grid $grid) {
            $grid->model()->with('user')->orderByDesc('id');
            $grid->column('user.tiktokno',trans('user.fields.tiktokno'))->display(function ($var){
                return $this->user_id."({$var})";
            });
            $grid->column('click');
            $grid->column('created_at')->display(function ($var){
                return Carbon::parse($var)->format('Y-m-d H');
            });

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('user_id',trans('user.fields.tiktokno'))->select(User::getUsers());
            });

            $grid->quickSearch(['user_id','user.tiktokno'])->placeholder(trans('user.fields.tiktokno'));




            $grid->disableViewButton();
            $grid->disableCreateButton();
            $grid->disableDeleteButton();
            $grid->disableRowSelector();
            $grid->showFilterButton();
            $grid->showFilter();

            $grid->showQuickEditButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Shopclick(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('click');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Shopclick(), function (Form $form) {
            $form->text('click');
        });
    }

}
